home *** CD-ROM | disk | FTP | other *** search
- This material is placed in the public domain by its author, William Couture.
- Copyright (c) 1986 by DDI. All Rights Reserved.
-
-
- CHARACTER GRAPHICS ROUTINES AVAILABLE
-
- GENERAL NOTES:
- All routines work in 320 x 200 4-color mode or 640 x 200 mode.
- COLOR is an integer between 0 and 3, inclusive, for 320 x 200 mode,
- and between 0 and 1, inclusive, for 640 x 200 mode (0 = background).
- Adding 128 to the color will XOR draw the character instead of
- plotting it. This will allow you to place characters on top of
- already drawn graphics screens without leaving holes in the picture.
- All the regular graphics routines are also available.
- CROW (Character ROW) is an integer between 1 and 25, inclusive.
- CCOL (Character COL) is an integer between 1 and 40, inclusive, for
- 320 x 200 mode, and between 1 and 80 for 640 x 200 mode.
- Do not let ANY routine draw anything beyond a screen edge.
- Character graphics can only be displaed in the spaces where normal
- characters would be on a 25 x 40 screen for 320 x 200 mode,
- and in the spaces where charcters would be on a 25 x 80
- screen for 640 x 200 mode.
- WCHAR is an integer between 0 and 127, inclusive. This is the index to
- the desired graphics character.
- CSHAPES is the name of an array which contains the character shapes.
-
-
-
-
-
- TYPE DEFINITIONS AND VARIABLES:
- Type CHARSET is a 1024 element of unsigned char, which holds the character
- images being used. If your compiler does not support the "unsigned
- char" type, make sure that the definition of char is an unsigned quantity.
-
- Type FILENAME is simply an 80 character array, used to pass a filename
- to the readcset and writecset functtions.
-
-
-
-
-
-
-
-
-
- ROUTINES:
-
- int readcset(cshapes,fname)
- unsigned char *cshapes
- char *fname
-
- Try to read the character set named filename into memory. The routine
- will return -1 if fname cannot be found, else it will return 0.
- This procedure is provided as C source in the file CGRAPH.C.
-
- example: errno = readcset(shapes,"myset.chr");
- if (errno)
- puts("Error - character set not found.");
- else
- run_program();
-
-
-
-
- int writecset(cshapes,fname)
- unsigned char *cshapes
- char *fname
-
- Write the current character set from memory to a disk file named fname.
- The routine returns a -1 if the file cannot be created, else it returns
- a 0.
- This procedure is provided as C source in the file CGRAPH.C.
-
-
- example: errno = writecset(shapes,"c:\stuff\saved.chr");
- if (errno)
- puts("Error - cannot open file to write character set.");
- else
- puts("Character set saved.");
-
-
-
- unsigned long getvect()
-
- Return the system's graphics character set pointer. This allows you to
- save the current pointer before setting up your own pointer. The return
- value is 32 bits, with the segment in the upper 16 bits and the offset in
- the lower 16 bits. It also has a companion routine, RESTOREVECT.
-
- example: unsigned long hold;
- unsigned int seg,ofs;
- main()
- {
- hold = getvect();
- ofs = (unsigned int) hold & 0xffff;
- seg = (unsigned int) ((hold >> 16) & 0xffff);
- }
-
-
-
- void restorevect(ofs,seg)
- int ofs,seg.
-
- Restore a previous graphics character set pointer.
-
-
-
- void setvect(cshapes)
- unsigned char *cshapes
-
- Set the system to display your graphics character set. This can be called
- any number of times, to display differenct character sets.
-
-
-
-
-
- void setbit(cshapes,wchar,row,col)
- unsigned char *cshapes
- int wchar,row,col
- row and col are integers from 0 to 7, inclusive
- Set the bit at row,col in WCHAR to ON.
-
-
-
- void clearbit(cshapes,wchar,row,col)
- unsigned char *cshapes
- int wchar,row,col
- row and col are integers from 0 to 7, inclusive
- Set the bit at row,col in WCHAR to OFF.
-
-
-
- void xorbit(cshapes,wchar,row,col)
- unsigned char *cshapes
- int wchar,row,col
- row and col are integers from 0 to 7, inclusive
- Set the bit at row,col in WCHAR to the opposite of its current state.
-
-
-
- void zerochar(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Set all bits in WCHAR to OFF.
-
-
-
- void fillchar(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Set all bits in WCHAR to ON.
-
-
-
- void inversechar(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Set all bits in WCHAR to the opposite of their current state.
-
-
-
- void copychar(cshapes,fromchar,intochar)
- unsigned char *cshapes
- int fromchar,intochar
- fromchar and intochar are two examples of WCHAR
- Make the graphics character intochar the same as fromchar.
-
-
-
- void horizflip(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Mirror WCHAR about its horizontal axis.
-
-
-
- void vertflip(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Mirror WCHAR about its vertical axis.
-
-
-
- void exchangerc(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Exchange rows and columns in WCHAR.
-
-
-
- void shiftdown(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR down 1 row. The bottom row is lost and the
- top row is set to blank.
-
-
-
- void shiftup(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR up 1 row. The top row is lost and the bottom
- row is set to blank.
-
-
-
- void shiftleft(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR left 1 column. The left column is lost and
- the right column is set to blank.
-
-
-
- void shiftright(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR right 1 column. The right column is lost and
- the left column is set to blank.
-
-
-
- void rotatedown(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR down 1 row. The bottom row wraps into the top
- row.
-
-
-
- void rotateup(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR up 1 row. The top row wraps into the bottom
- row.
-
-
-
- void rotateleft(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR left 1 column. The left column wraps into
- the right column.
-
-
-
- void rotateright(cshapes,wchar)
- unsigned char *cshapes
- int wchar
-
- Move the picture in WCHAR right 1 column. The right column wraps into
- the left column.
-
-
-
- void grchar(wchar,color)
- int wchar,color
- color is an int from 0 to 3 in 320 x 200 mode, and
- from 0 to 1 in 640 x 200 mode
- Plot the graphics char WCHAR at the current cursor position in COLOR.
- Adding 128 (0x80 in hex) to the value of WCHAR will plot the
- corresponding regular character, instead of the graphics character.
- Adding 128 (0x80 in hex) to the color will XOR draw the character,
- placing it on top of the current screen image.
-
-
-
- void gratchar(crow,ccol,wchar,color)
- int crow,ccol,wchar,color
- crow and ccol are the screen locations. 320 x 200
- mode supports a 40 x 25 screen, and 640 x 200 mode
- supports a 80 x 25 screen.
- color is an int from 0 to 3 in 320 x 200 mode, and
- from 0 to 1 in 640 x 200 mode.
- Plot the graphics char WCHAR at CROW,CCOL in COLOR.
- Adding 128 (0x80 in hex) to the value of WCHAR will plot the
- corresponding regular character, instead of the graphics character.
- Adding 128 (0x80 in hex) to the color will XOR draw the character,
- placing it on top of the current screen image.
-
-
-
- void printbanner(crow,ccol,msg,length,color)
- int crow,ccol
- int *msg
- int length,color
- crow and ccol are the screen locations. 320 x 200
- mode supports a 40 x 25 screen, and 640 x 200 mode
- supports a 80 x 25 screen.
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- color is an int from 0 to 3 in 320 x 200 mode, and
- from 0 to 1 in 640 x 200 mode.
- Move the cursor to CROW,CCOL and display the LENGTH graphics characters
- from MSG across the screen in COLOR. Please note that adding 128 (0x80
- in hex) to the color will XOR draw the characters, placing them on top
- of the current screen image.
- This procedure is provided as C source in the file CGRAPH.C.
-
-
-
-
-
- void bannerleft(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Treat LENGTH elements of MSG as one extended graphics character and
- rotate it left 1 column. The column rolled off the left is wrapped back
- on the right.
-
-
-
-
- void bannerright(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Treat LENGTH elements of MSG as one extended graphics character and
- rotate it right 1 column. The column rolled off the right is wrapped back
- to the left.
-
-
-
- void bannerup(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Move LENGTH elements of MSG up 1 row. The row rotated off the top
- wraps back to the bottom. Note that any character may be individually
- scrolled via the rotatexxxx() procedures above.
-
-
-
- void bannerdown(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Move LENGTH elements of MSG down 1 row. The row rotated off the
- bottom wraps back to the top. Note that any character may be individually
- scrolled via the rotatexxxx() functions above.
-
-
- example:
-
- /*
- Example program #1 from the CGRAPH documentation.
- */
- /*
- Compile this with your compiler, then Link it with the supplied object
- modules.
- */
- #include <stdio.h>
- #include <chedit.h> /* Defines of the CHEDIT functions. Use it if your
- compiler does strong type checking. */
- #include <cgraph.c> /* The READCSET, WRITECSET, PRINTBANNER, and
- PRINTCOLUMN routines are C source, included in
- this file. */
- #define CYAN 1
- #define MAGENTA 2
- #define WHITE 3 /* color definitions */
-
- unsigned char shapes[1024]; /* the array to hold the character shapes */
- int message[20]; /* the array to hold the message to be plotted */
- int errno; /* to hold the return value from READCSET */
- int i,m; /* loop indices */
- unsigned long hold; /* temporary storage for saving the system
- graphics character vector */
- unsigned int ofs,seg; /* the ofset and segment of the saved system
- vector */
-
- main()
- {
- errno = readcset(shapes,"alpha.chr");
- /* read the character set */
- if (!errno) /* if all ok */
- {
- grmode(4); /* set to 320 x 200 graphics */
- /* Use the routine appropriate to your compiler */
- message[0] = 65; /* graphics character 65 */
- message[1] = 67; /* etc. */
- message[2] = 69;
- hold = getvect(); /* save the system vector */
- ofs = (unsigned int) (hold & 0xffff);
- seg = (unsigned int) ((hold >> 16) & 0xffff);
- setvect(shapes); /* and insert our own */
- printbanner(2,5,message,2,CYAN);
- /* print the message in color 1, cyan, at 2,5
- on the screen. Note that this displays only
- the first 2 characters, so the 3rd is "hidden" */
- for (i = 0; i < 8*3*20; i++)
- /* rotate through all 8 columns of the 3 chars
- 20 times */
- {
- for (m = 0; m < 1500; m++) ;
- /* waste a little time */
- bannerleft(shapes,message,3);
- /* rotate all left so all characters take turns
- being hidden */
- printbanner(2,5,message,2,CYAN);
- /* and display it again */
- }
- for (m = 0; m < 30000; m++) ;
- /* one last time delay */
- restorevect(ofs,seg); /* put the system vector back */
- grmode(3); /* turn the graphics off */
- /* use the routine appropriate to your compiler */
- } /* end of the if */
- } /* end of the program */
-
-
-
-
-
-
-
-
- void printcolumn(crow,ccol,msg,length,color)
- int crow,ccol
- int *msg
- int length,color
- crow and ccol are the screen locations. 320 x 200
- mode supports a 40 x 25 screen, and 640 x 200 mode
- supports a 80 x 25 screen.
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- color is an int from 0 to 3 in 320 x 200 mode, and
- from 0 to 1 in 640 x 200 mode.
- Move the cursor to CROW,CCOL and display the LENGTH graphics chatacters
- from MSG down the screen in COLOR. Please note that adding 128 (0x80
- in hex) to the color will XOR draw the characters, placing them on top
- of the current screen image.
- This procedure is provided as C source in the file CGRAPH.C.
-
-
-
- void columnup(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Treat LENGTH elements of MSG as one extended graphics character and
- rotate it 1 row up. The row that rolls off the top wraps to the bottom.
-
-
-
- void columndown(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Treat LENGTH elements of MSG as on extended graphics character and
- rotate it 1 row down. The row that rolls off the bottom wraps to the top.
-
-
-
- void columnleft(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Move LENGTH elements of MSG left 1 column. The column rotated off the
- left wraps to the right. Note that any element of the column may be
- scrolled by the rotatexxxx() functions above.
-
-
-
- void columnright(cshapes,msg,length)
- unsigned char *cshapes
- int *msg
- int length
- MSG is an array of integers which contains the WCHAR
- codes for the banner
- LENGTH is the number of elements in MSG
- Move LENGTH elements of MSG right 1 column. The column rotated off
- the right wraps to the left. Note that any element of the column may be
- scrolled by the rotatexxxx() functions above.
-
-
-
-
-
-
- example:
-
- /*
- Example program #2 from the CGRAPH documentation.
- */
- /*
- Compile this with your compiler, then Link it with the supplied object
- modules.
- */
- #include <stdio.h>
- #include <chedit.h> /* Defines of the CHEDIT functions. Use it if your
- compiler does strong type checking. */
- #include <cgraph.c> /* The READCSET, WRITECSET, PRINTBANNER, and
- PRINTCOLUMN routines are C source, included in
- this file. */
- #define CYAN 1
- #define MAGENTA 2
- #define WHITE 3 /* color definitions */
-
- unsigned char shapes[1024]; /* character set storage */
- int window1[6],window2[6],window3[6];
- /* the character "strings" to be displayed */
- int i,m,n,p,errno,delay,delta;
- /* loop indices and such */
- char ch; /* for user response */
-
- unsigned long hold; /* temporary storage for saving the system
- graphics character vector */
- unsigned int ofs,seg; /* the ofset and segment of the saved system
- vector */
-
- main()
- {
- errno = readcset(shapes,"slotmchn.chr");
- /* read the character set */
- if (!errno) /* if all is ok */
- {
- grmode(4); /* set 320 x 200 graphics */
- /* use the routine appropriate to your compiler */
- cursor_pos(20,3); /* use the routine appropriate to your compiler */
- puts("Press Return to roll again");
- /* let the user know what to do */
- hold = getvect(); /* save the system vector */
- ofs = (unsigned int) (hold & 0xffff);
- seg = (unsigned int) ((hold >> 16) & 0xffff);
- setvect(shapes); /* and put in our own */
- for (i = 0; i < 5; i++) /* set up the bells and whistles (and cherries */
- { /* and lemons and...) */
- window1[i] = i; /* use these characters */
- window2[i] = i+10;
- window3[i] = i+20;
- }
- for (i = 0; i < 5; i++)
- {
- copychar(shapes,window1[i],window2[i]);
- /* copy the pictures from window1 to window 2 */
- copychar(shapes,window1[i],window3[i]);
- /* and window 3 */
- }
- do /* now do the display */
- {
- i = 8*((rand() % 11)+5);
- /* spin window 1 5 to 15 times (8 rows/char) */
- m = i+8*((rand() % 6)+5);
- /* window 2 spins a little longer */
- n = m+8*((rand() % 6)+5);
- /* and window 3 longer yet */
- printcolumn(5,10,window1,1,WHITE);
- /* display the initial characters */
- printcolumn(5,15,window2,1,WHITE);
- printcolumn(5,20,window3,1,WHITE);
- /* Note: for displaying 1 character, gratchar */
- /* could also be used. */
- /* e.g. gratchar(5,x,windowx[0],WHITE) */
- delay = 0; /* start off fast */
- do
- {
- if (i) /* each window rolls its own number of times */
- {
- columndown(shapes,window1,5); /* roll window */
- i--; /* count it */
- if (i == 0)
- delay += 50;
- /* if this window is not going to roll */
- /* anymore, make up for the processing */
- /* time lost not updating it */
- }
- if (m) /* this looks just like the previous one */
- {
- columndown(shapes,window2,5);
- m--;
- if (m == 0)
- delay += 50;
- }
- columndown(shapes,window3,5);
- n--; /* the 3rd window needs no fancy processing, as we
- know it will be spinning to the very end */
- for (delta = 0; delta < delay; delta++); /* waste a little time */
- delay += 10; /* waste a little more time next time */
- printcolumn(5,10,window1,1,WHITE); /* update the windows */
- printcolumn(5,15,window2,1,WHITE);
- printcolumn(5,20,window3,1,WHITE);
- } while (n); /* end of inner repeat loop */
- ch = getchar(); /* get the users response */
- /* anything fancier would be compiler dependent */
- } while (ch == '\n'); /* and repeat until it is not a CR */
- restorevect(ofs,seg); /* put the system vector back */
- grmode(3); /* restore the regular screen */
- } /* end of the if statement */
- } /* end of the program */
-
-
-
-
-
-
-
- void loadega(cshapes,num,size,offset)
- unsigned char *cshapes
- int num,size,offset
-
- Load the character set specified by CSHAPES as the resident EGA character
- set. NUM is the number of shapes to load into the character set (an
- entire set need not be loaded at once), SIZE is the number of rows in
- a character, and OFFSET is the location to start loading at (for example,
- the offset to start loading at an upper case A is 65). The loading
- always starts at the 0th element of CSHAPES, so you cannot load a
- character from the middle of a character set without loading the
- characters that come before it.
- It should be noted that loading ANY part of a character set, even if it
- is not displayed on the screen (for example, loading the extended ASCII
- characters), will re-calculate the number of rows on the screen, and set
- the character size to the size specified. Thus, if you load an 8 x 8
- character set into the extended ASCII characters, the computer will
- display the regular charcters as 8 x 8 as well, even though they have an
- 8 x 14 character set loaded.
-
-
- void loadega14(cshapes1,cshapes2,num,offset)
- unsigned char *cshapes1,*cshapes2
- int num,offset
-
- WARNING: THIS ROUTINE IS A STACK HOG!
- You will need at least 2K (2048 bytes) of AVAILABLE stack
- to use this routine, and more is recommended to be on the
- safe side!
-
- Take two CHEDIT character sets in the format described below, and load
- them as the resident EGA character set in 8 x 14 format. NUM is the
- number of shapes to load into the character set (an entire set need not
- be loaded at once, and OFFSET is the location to start loading at (for
- example, the offset to start loading at an upper case A is 65). The
- loading always starts at the 0th element of CSHAPES1, so you cannot load
- a character from the middle of a character seet without loading the
- characters that come before it.
- It should be noted that loading ANY part of a character set, even if it
- is not displayed on the screen (for example, loading the extended ASCII
- characters), will re-calculate the number of rows on the screen, and set
- the character size to the size specified. Thus, if you load an 8 x 14
- character set into the extended ASCII characters, the computer will
- display the regular charcters as 8 x 14 as well, even though they have an
- 8 x 8 character set loaded.
- This function is provided as C source in the file EGA.C as an example.
-
- Please note that this is a "stopgap" function, included to provide
- minimal support for EGA until an EGA version of CHEDIT is written.
-
- CHARACTER SET FORMAT:
- The format of the two character sets is that each contains 64 characters that
- are two "standard" characters high (the bottom two rows should be unused in
- the second character), easily created via the Multiple character editing
- option of CHEDIT. The characters must not be successive, but instead should
- be "on top" of each other as seen in the character set display at the top of
- CHEDIT. i.e.
-
- _____________________________ ...
- | | | |
- | upper | upper | upper |
- | 0 | 1 | 2 |
- | | | |
- | | | |
- | | | |
- |________|________|________|__ ...
- | | | |
- | lower | lower | lower |
- | 0 | 1 | 2 |
- | | | |
- |________|________|________|
- | blank | blank | blank |
- |________|________|________|__ ...
- | | | |
- . . . .
- . . . .
- . . . .
-
- The space labeled "blank" is the bottom 2 rows of the lower characters. If
- are not blank, they will simply be ignored.
-